<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <title>搜索 - 知识库</title>
    <style>
        body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f5f5f5; color: #1a1a1a; }
        .container { max-width: 900px; margin: 40px auto; background: #fff; border-radius: 12px; box-shadow: 0 4px 20px #0001; padding: 32px; }
        .search-form { display: flex; gap: 12px; margin-bottom: 32px; }
        .search-input { flex: 1; padding: 12px 16px; border: 2px solid #e5e5e5; border-radius: 8px; font-size: 16px; }
        .search-btn { padding: 12px 32px; background: #1a1a1a; color: #fff; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; }
        .section-title { font-size: 20px; font-weight: 600; margin: 32px 0 16px 0; }
        .result-table { width: 100%; border-collapse: separate; border-spacing: 0; background: #fafafa; border-radius: 8px; box-shadow: 0 2px 8px #0001; }
        .result-table th, .result-table td { padding: 12px 8px; border-bottom: 1px solid #eee; }
        .result-table th { background: #f5f5f5; font-weight: 600; }
        .result-table tr:last-child td { border-bottom: none; }
        .empty-tip { color: #888; text-align: center; padding: 32px 0; }
        a { color: #1a1a1a; text-decoration: none; }
        a:hover { text-decoration: underline; }
    </style>
</head>
<body>
<div class="container">
    <form class="search-form" action="/search" method="get">
        <input type="text" class="search-input" name="q" value="${param.q}" placeholder="输入文档标题或空间名称..." required />
        <button type="submit" class="search-btn">🔍 搜索</button>
    </form>

    <div>
        <div class="section-title">文档结果</div>
        <c:choose>
            <c:when test="${not empty docResults}">
                <table class="result-table">
                    <thead>
                        <tr><th>标题</th><th>空间</th><th>作者</th><th>创建时间</th><th>操作</th></tr>
                    </thead>
                    <tbody>
                        <c:forEach var="doc" items="${docResults}">
                            <tr>
                                <td>${doc.title}</td>
                                <td>${doc.spaceName}</td>
                                <td>${doc.authorName}</td>
                                <td>${fn:substring(doc.createdAt, 0, 19)}</td>
                                <td><a href="/document/detail/${doc.id}">查看</a></td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>
            </c:when>
            <c:otherwise>
                <div class="empty-tip">没有找到相关文档。</div>
            </c:otherwise>
        </c:choose>
    </div>

    <div>
        <div class="section-title">空间结果</div>
        <c:choose>
            <c:when test="${not empty spaceResults}">
                <table class="result-table">
                    <thead>
                        <tr><th>空间名称</th><th>描述</th><th>可见性</th><th>操作</th></tr>
                    </thead>
                    <tbody>
                        <c:forEach var="space" items="${spaceResults}">
                            <tr>
                                <td>${space.name}</td>
                                <td>${space.description}</td>
                                <td>${space.visibility == 'public' ? '公开' : '私有'}</td>
                                <td><a href="/space/detail/${space.id}">查看</a></td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>
            </c:when>
            <c:otherwise>
                <div class="empty-tip">没有找到相关空间。</div>
            </c:otherwise>
        </c:choose>
    </div>
</div>
</body>
</html> 